<?php
namespace Home\Controller;
use Think\Controller;
class PracticeController extends Controller {
    public function index(){
      $this->display();
    }

public function practicelist(){
 $practiceModel=M('Practices');
  $this->practices=$practiceModel->field('name,groupname,pfile,id')->select();
  $pm=$practiceModel->query('select * from practices order by hit DESC ');
   $this->pm=$pm;
  $this->display();
 }

public function practiceDetail($id){
	$groupModel=M('Practices');
	$this->groups=$groupModel->select($id);
	$users=$groupModel->query('update practices set hit=hit+1 where id='.$id);
	$this->members=$groupModel->join('Stuprac on practices.id=Stuprac.pid')->where('practices.id='.$id)->select();
  	$this->display();
}

public function addPracticeUser(){
   $groupModel=M('Stuprac');
   $groupModel->create();
   $data['pid']=$_GET['id'];
   $data['stunum']=session('user.stunum');
   $groupModel->atime=date('Y-m-d');  
   if ($groupModel->where($data)->select()) {
     $this->error('已申请');
   }
   else
   {
  if ($groupModel->data($data)->add()) {
    $this->success('申请成功');
   }
   else
    $this->error('申请失败');
}
}
}?>
